﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class NativeAOT
{
    [UnmanagedCallersOnly(EntryPoint = "lags")]
    public static unsafe double lags(IntPtr f_x_ptr)
    {
        f_x = Marshal.GetDelegateForFunctionPointer<delegatefunc_x>(f_x_ptr);

        return lags();
    }

    /// <summary>
    /// 拉盖尔_高斯求积法
    /// f计算被积函数值f(x)的函数名。
    /// </summary>
    /// <returns>函数返回积分值。</returns>
    public static unsafe double lags()
    {
        int i;
        double x, g;
        double[] t = new double[5] {
            0.26355990,1.41340290,3.59642600,7.08580990,12.64080000
        };
        double[] c = new double[5] {
            0.6790941054,1.638487956,2.769426772,4.315944000,7.104896230
        };
        g = 0.0;
        for (i = 0; i <= 4; i++)
        {
            x = t[i];
            g = g + c[i] * f_x(x);
        }
        return (g);
    }

    /*
      int main()
      { 
          double lagsf(double);
          cout <<"g = " <<lags(lagsf) <<endl;
          return 0;
      }
    // 计算被积函数值
      double lagsf(double x)
      { 
          return(x*exp(-x));
      }
    */
}

